package net.wanho.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Author：汤小洋
 * Date：2025-06-13 14:30
 * Description：<描述>
 */
@WebServlet("/world")
// @WebServlet("*.do")
public class WorldServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");

        String username = req.getParameter("username");
        String password = req.getParameter("password");
        int age = Integer.parseInt(req.getParameter("age"));
        System.out.println(username);
        System.out.println(password);
        System.out.println(age);

        System.out.println("请求方式：" + req.getMethod());


        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();

        // int i = 5/ 0;

        /**
         * 判断账号和密码
         */
        if("admin".equals(username) && "123".equals(password)){
            out.print("<html>");
            out.print("<head>");
            out.print("<body>");
            out.print("登录成功！");
            out.print("</body>");
            out.print("</head>");
            out.print("</html>");
            out.close();
            // resp.sendRedirect("list.html");
        }else{
            out.print("登录失败！");
            out.close();
        }
    }
}
